package com.xiebishe.mylibrary.common.pageStatus;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;

import com.xiebishe.mylibrary.R;


public class EmptyView extends LinearLayout {

    private OnClickListener listener;

    private ImageView img_head;
    private TextView tv_tip;

    public void setLoadingListener(OnClickListener loadingListener) {
        this.listener = loadingListener;
    }

    public EmptyView(Context context) {
        super(context);
        initView();
    }

    public EmptyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public void initView() {
        RelativeLayout mContainer = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.page_empty, null);
        img_head=mContainer.findViewById(R.id.im_icon);
        tv_tip=mContainer.findViewById(R.id.tv_text);
        addView(mContainer, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        this.setOnClickListener(v -> {
            if (listener != null) {
                listener.onClick(v);
            }
        });

    }


    public void setEmptyTip(CharSequence text) {
        if (tv_tip != null) {
            tv_tip.setText(text);
        }
    }

    public void setEmptyViewHead(@DrawableRes int res) {
        if (img_head != null) {
            img_head.setImageResource(res);
        }
    }
}
